package WorkTest;

public class a{
    public static void main(String[] args) {
        String s="abc";
        System.out.println(new a().jiusan(s));
    }

    String jiusan(String str){
        if(str.length()<2)return str.substring(0,1);
        if(str.length()==2)return str;

        char[] cs=str.toCharArray();
        int l=0;
        int r=0;
        int max=0;
        int bl=0;
        int br=0;
        for(int i=1;i<cs.length-1;i++){
            if(cs[i]==cs[i+1]){
                l=i;
                r=i+1;
                while(l>=0&&r<=cs.length-1&&cs[l--]==cs[r++]){};
                l++;
                r--;
                if(max<r-l){
                    br=r;
                    bl=l;
                    max=r-l;
                }
            }

            if(cs[i-1]==cs[i]){
                l=i-1;
                r=i;
                while(l>=0&&r<=cs.length-1&&cs[l--]==cs[r++]){};
                l++;
                r--;
                if(max<r-l){
                    br=r;
                    bl=l;
                    max=r-l;
                }
            }
            if(cs[i-1]==cs[i+1]){
                l=i-1;
                r=i+1;
                while(l>=0&&r<=cs.length-1&&cs[l--]==cs[r++]){};
                l++;
                r--;
                if(max<r-l){
                    br=r;
                    bl=l;
                    max=r-l;
                }
            }

        }
        return str.substring(bl,br+1);
    }
}